package prototype.example;

import java.util.Random;

/**
 * @Author：LJ
 * @Description：
 * @Date: 2017/11/28
 * @Modified By:
 */
public class Client {
    private static int MAX_COUNT = 6;

    public static void main(String[] args) {
        int i = 0;
        Mail mail = new Mail(new AdvTemplate());
        mail.setTail("xxx银行版权所有");
        while (i < MAX_COUNT) {
            mail.setAppellation(getRandString(5) + " 先生(女士)");
            mail.setReceiver(getRandString(5) + "@" + getRandString(8) + ".com");
            Mail clone=mail.clone();
            sendMail(clone);
            i++;
        }
    }

    public static void sendMail(Mail mail) {
        System.out.println("标题:" + mail.getTail() + "\t收件人:" + mail.getReceiver() + "\t...发送成功!");
    }

    public static String getRandString(int maxLength) {
        String source = "abcdefghijklmnopqrstuvwsyz";
        StringBuffer stringBuffer = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < maxLength; i++) {
            stringBuffer.append(source.charAt(random.nextInt(source.length())));
        }
        return stringBuffer.toString();
    }
}
